{{Extend "layout"}}
{{Block "title"}}{{"资讯管理"|T}}{{/Block}}
{{Block "breadcrumb"}}
{{Super}}
{{if gt Stored.productId 0}}
<li><a href="__BACKEND__/official/pay/product_index">{{"产品列表"|T}}</a></li>
{{end}}
<li class="active">{{"资讯管理"|T}}</li>
{{/Block}}
{{Block "main"}}
<div class="row">
	<div class="col-md-12">
		<div class="block-flat">
			<div class="header">
				<a href="__BACKEND__/official/news_add?productId={{Stored.productId}}" class="btn btn-success pull-right">
					<i class="fa fa-plus"></i>
					{{"添加资讯"|T}}
				</a>
				{{if gt Stored.productId 0}}
				<a href="__BACKEND__/official/product_news_tags_index?productId={{Stored.productId}}" class="btn btn-primary pull-right">
					<i class="fa fa-tags"></i>
					{{"资讯标签"|T}}
				</a>
				{{end}}
				<h3>{{"资讯列表"|T}}</h3>
			</div>
			<div class="content">
				<div class="table-responsive">
				<table class="table no-border hover">
					<thead class="no-border">
						<tr>
							<th style="width:40px;"><strong>ID</strong></th>
							<th style="width:50px"><strong>{{"图"|T}}</strong></th>
							<th><strong>{{"标题"|T}}</strong></th>
							<th><strong>{{"产品"|T}}</strong></th>
							<th style="width:80px"><strong>{{"喜欢"|T}}</strong></th>
							<th style="width:80px"><strong>{{"评论"|T}}</strong></th>
							<th style="width:80px"><strong>{{"显示"|T}}</strong></th>
							<th style="width:170px"><strong>{{"时间"|T}}</strong></th>
							<th style="width:120px" class="text-center"><strong>{{"操作"|T}}</strong></th>
						</tr>
					</thead>
					<tbody class="no-border-y">
                        {{range $k,$v := Stored.listData}}
						<tr>
							<td>{{$v.Id}}</td>
							<td class="no-padding"><a href="__FRONTEND__/news/detail/{{$v.Id}}" target="_blank"><img style="width:50px;height:50px" src="{{$v.Image|Default "__ASSETS__/images/user_128.png"}}" onerror="this.src='__ASSETS__/images/user_128.png';" /></a></td></td>
							<td><a href="__FRONTEND__/news/detail/{{$v.Id}}" target="_blank">{{$v.Title}}</a></td>
							<td><a href="__FRONTEND__/product/detail/{{$v.Product.Ident}}" target="_blank">{{$v.Product.Name}}</a></td>
							<td>
								<span class="text-success"><i class="fa fa-thumbs-up"></i>{{$v.Likes}}</span><br />
								<span class="text-danger"><i class="fa fa-thumbs-down"></i>{{$v.Hates}}</span>
							</td>
							<td>
								<div class="checkbox checkbox-success no-margin-y">
									&nbsp;<input id="checkbox-closeComment-{{$k}}" class="styled switch-closeComment" type="checkbox" data-id="{{$v.Id}}" data-close-comment="{{$v.CloseComment}}"{{if eq $v.CloseComment "N"}} checked="checked"{{end}} value="N" /><label for="checkbox-closeComment-{{$k}}">{{"开"|T}}</label>
								</div>
								<a href="__BACKEND__/official/comment_list?targetId={{$v.Id}}"><i class="fa fa-comments"></i>{{$v.Comments}}</a>
							</td>
							<td>
								<div class="checkbox checkbox-success no-margin-y">
									&nbsp;<input id="checkbox-{{$k}}" class="styled switch-display" type="checkbox" data-id="{{$v.Id}}" data-display="{{$v.Display}}"{{if eq $v.Display "Y"}} checked="checked"{{end}} value="Y" /><label for="checkbox-{{$k}}">{{"开"|T}}</label>
								</div>
								<i class="fa fa-eye"></i>{{$v.Views}}
							</td>
							<td>
								{{"创建"|T}}: {{(Date $v.Created).Format "2006-01-02 15:04:05"}}<br />
								{{"修改"|T}}: {{if gt $v.Updated 0}}{{(Date $v.Updated).Format "2006-01-02 15:04:05"}}{{else}}-{{end}}
							</td>
							<td class="text-center">
							<a class="label label-default" href="__BACKEND__/official/news_add?productId={{Stored.productId}}&copyId={{$v.Id}}" title="{{"复制"|T}}" data-toggle="tooltip"><i class="fa fa-copy"></i></a>
							<a class="label label-success" href="__BACKEND__/official/news_edit?productId={{Stored.productId}}&id={{$v.Id}}" title="{{"编辑"|T}}" data-toggle="tooltip"><i class="fa fa-pencil"></i></a> 
							<a class="label label-danger" href="__BACKEND__/official/news_delete?productId={{Stored.productId}}&id={{$v.Id}}" onclick="return confirm('{{"真的要删除吗？"|T}}');" title="{{"删除"|T}}" data-toggle="tooltip"><i class="fa fa-times"></i></a>
							</td>
						</tr>
                        {{end}}
					</tbody>
				</table>		
				</div>
				{{Stored.pagination.Render}}
			</div>
		</div>				
	</div>
</div>
{{/Block}}
{{Block "footer"}}
<script>
$(function(){
	$('input.switch-display').on('click',function(r){
		var that=$(this),display=that.data('display')=='Y'?'N':'Y';
		$.get(BACKEND_URL+'/official/news_edit?productId={{Stored.productId}}',{
			display:display,
			id:that.data('id')
		},function(r){
			if(r.Code==1){
				that.data('display',display);
				that.prop('checked',display=='Y');
			}
			App.message({title:'{{"系统消息"|T}}',text:r.Info,time:5000,sticky:false,class_name:r.Code==1?'success':'error'});
		},'json');
	});
	$('input.switch-closeComment').on('click',function(r){
		var that=$(this),closeComment=that.data('close-comment')=='N'?'Y':'N';
		$.get(BACKEND_URL+'/official/news_edit?productId={{Stored.productId}}',{
			closeComment:closeComment,
			id:that.data('id')
		},function(r){
			if(r.Code==1){
				that.data('close-comment',closeComment);
				that.prop('checked',closeComment=='N');
			}
			App.message({title:'{{"系统消息"|T}}',text:r.Info,time:5000,sticky:false,class_name:r.Code==1?'success':'error'});
		},'json');
	});
});
</script>
{{/Block}}